n=int(input())

a=set()
b=set()

for i in range(0,n):
    x,y=map(int,input().split())
    for j in range(x,y):
        a.add(j)
for i in range(0,n):
    x,y=map(int,input().split())
    for j in range(x,y):
        b.add(j)

c=a&b

print(len(c))

